//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#ifndef _ClusterByAPALINGO_H
#define	_ClusterByAPALINGO_H
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#include <time.h>
#include <mpi.h>

#include "ListSmile.h"
#include "APCluster.h"
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#define	ARRAYSIZE    600000
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
class ClusterByAPALINGO {
    
  private:

    time_t        initialTime;
    time_t        finalTime;

    int           err;
    int           rank;
    int           sizeRank;

    int           maxIterConv;

    MPI_Request   reqs[ARRAYSIZE];
    MPI_Status    stat;

    ListSmile*    molDB;

    String*       filename;
    String*       initialFileName;
    String*       nameLogFile;

    bool          convergence;
    bool          condLogFile;

  protected:

    char*         ShowTime(char*);

    int           ClusteringAPA(long);
    int           IterativeClusteringAPA(long);
    int           JoinClusterResult(char*, int);
    int           JoinIterativeClusterResult(char*, int);

    int           prepareNewDB(char*);

    bool          AnalizeConvergence(int, double&);
    double        AnalizeConvergenceParallel(int);
    
    bool          AnalizeConvergenceClusterSim(int, double&);
    double        AnalizeConvergenceParallelClusterSim(int);
    
  public:
      
    ClusterByAPALINGO();
    ~ClusterByAPALINGO();

    void          InitialTime(time_t);
    void          FinalTime(time_t);

    void          MolDB(ListSmile*);
    
    void          Filename(String*);
    void          NameLogFile(String*);

    void          CondLogFile(bool);

    void          MaxIterConv(int);
    
    time_t        InitialTime();
    time_t        FinalTime();

    ListSmile*    MolDB();

    String*       Filename();
    String*       InitialFileName();
    String*       NameLogFile();

    bool          Convergence();
    bool          CondLogFile();

    void          Err(int);
    void          Rank(int);
    void          SizeRank(int);
    
    int           Err();
    int           Rank();
    int           SizeRank();
    
    int           MaxIterConv();
    
    MPI_Request   Reqs(int);
    MPI_Status    Stat();

    bool          ClusteringDatabaseParallel(int, char**);

};
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
#endif
//---------------------------------------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------------------//

